Micron Document
Livres et Wikis | Archives | Info


JavaScript syntax
part 26/43 Β· 161.3 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Rest parameters are similar to Javascript's arguments object, which is
an array-like object that contains all of the parameters (named and
unnamed) in the current function call. Unlike arguments, however, rest
parameters are true Array objects, so methods such as .slice() and
.sort() can be used on them directly.

Comparison

| == | equal |
|---|---|
| != | not equal |
| > | greater than |
| >= | greater than or equal to |
| < | less than |
| <= | less than or equal to |
| === | identical (equal and of same type) |
| !== | not identical |

Variables referencing objects are equal or identical only if they
reference the same object:

const obj1 = {a: 1};
const obj2 = {a: 1};
const obj3 = obj1;
console.log(obj1 == obj2); //false
console.log(obj3 == obj1); //true
console.log(obj3 === obj1); //true

See also String.

Logical

JavaScript provides four logical operators:

β€’ unary negation (NOT = !a)
β€’ binary disjunction (OR = a || b) and conjunction (AND = a && b)
β€’ ternary conditional (c ? t : f)

In the context of a logical operation, any expression evaluates to true
except the following:

β€’ Strings: "", '',
β€’ Numbers: 0, -0, NaN,
β€’ Special: null, undefined,
β€’ Boolean: false.

The Boolean function can be used to explicitly convert to a primitive of
type Boolean:

// Only empty strings return false
console.log(Boolean("") === false);
console.log(Boolean("false") === true);
console.log(Boolean("0") === true);
// Only zero and NaN return false
console.log(Boolean(NaN) === false);
console.log(Boolean(0) === false);
console.log(Boolean(-0) === false); // equivalent to -1*0
console.log(Boolean(-2) === true);
// All objects return true
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────